package com.xxx.controller;


import com.xxx.pojo.Department;
import com.xxx.pojo.RespBean;
import com.xxx.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  部门设置
 * </p>
 *
 * @author WXH
 * @since 2022-02-23
 */
@RestController
@RequestMapping("system/basic/department")
@Api(value = "部门管理",tags = "部门管理")
public class DepartmentController {
    @Autowired
   private IDepartmentService departmentService;




    @ApiOperation("获取所有部门")
    @GetMapping("/list")
    public List<Department> getAllInfo(@ApiParam@RequestParam Integer deptId){
        return departmentService.getAllInFo(deptId);
    }
    @ApiOperation("添加部门")
    @PostMapping("/add")
    public RespBean add(@RequestBody Department department){

        int status=departmentService.add(department);
        if (status == 0){
            return RespBean.error("添加失败！！");
        }
        return RespBean.sucess("添加成功！！");
    }
//    采用项目存储过程的方式添加和删除部门
    @ApiOperation("添加部门")
    @PostMapping("/addDept")
    public RespBean addDept(@RequestBody Department department){
        return departmentService.addDept(department);
    }

    @ApiOperation("删除部门")
    @PostMapping("/deleteDept")
    public RespBean deleteDept(@RequestParam("id") Integer id ){
        return departmentService.deleteDept(id);
    }

}
